# -*- coding: utf-8 -*-
import os
#import numpy as np
import logging
#from functools import reduce
#work_path = ''
#logging.basicConfig(level=logging.INFO,
#                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
#                    datefmt='%a, %d %b %Y %H:%M:%S',
#                    filename=work_path+'\\factorData.log',
#                    filemode='w')
dirs = 'logs'
if not os.path.exists(dirs):
    os.makedirs(dirs)
logging.basicConfig(filename='%s/info_leetcode.log' % dirs, level=logging.INFO,
                    format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
print(logging.__file__)
logger.info('aaa')
'''
链表怎么跑啊?ide怎么去运行?
链表就像C的指针,node就是一个内存地址,node.val就是这个内存地址的值
node.next就是下一个地址'''

# 此为非递归的合并有序链表
class Solution:
    def mergeTwoLists(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        head = ListNode(0)
        first = head
        while l1!=None and l2!=None:
            if l1.val <= l2.val:
                head.next = l1
                l1 = l1.next
            else:
                head.next = l2
                l2 = l2.next
            head = head.next
        if l1 != None:
            head.next = l1
        elif l2 != None:
            head.next = l2
        return first.next
    
# =============================================================================
# 这个递归太难了!!!太难了~~
# # 此为递归方法合并两个有序链表
# class Solution:
#     def mergeTwoLists(self, l1, l2):
#         """
#         :type l1: ListNode
#         :type l2: ListNode
#         :rtype: ListNode
#         """
#         if l1==None and l2==None:
#             return None
#         if l1==None:
#             return l2
#         if l2==None:
#             return l1
#         if l1.val<=l2.val:
#             l1.next=self.mergeTwoLists(l1.next,l2)
#             return l1
#         else:
#             l2.next=self.mergeTwoLists(l1,l2.next)
#             return l2
# =============================================================================
        
sss = Solution()
qqq = sss.mergeTwoLists([1,2,4],[1,3,4])  
# =============================================================================
# # 这个和leetcode不太一样,也没细看
# class ListNode():
#     def __init__(self,x):
#         self.val = x
#         self.next = None
# 
# def function(listNode1,listNode2):
#     p = merge = ListNode(0)
#     while listNode1 and listNode2:
#         if listNode1.val > listNode2.val:
#             merge.next = listNode2
#             listNode2 = listNode2.next
#         elif listNode2.val >= listNode1.val:
#             merge.next = listNode1
#             listNode1.next = listNode1
#         merge.next = merge
#     #注意：当由于其中一链表listNode1或者listNode2为null，导致跳出while循环时，
#     #此时，还需要将另一不为null的链表的后续部分赋给合并链表。 
#     merge = listNode1 or listNode2
#     return p.next
# =============================================================================


# =============================================================================
# # 这个也没懂
# # 对链表遍历，需保存上一个指针和下一个指针。在遍历过程中理清三者关系，注意不要互相覆盖即可。
# class Solution(object):
#     def reverseList(self, head):
#         """
#         :type head: ListNode
#         :rtype: ListNode
#         """
#         if head==None:
#             return []
#         last_temp = None
#         temp = head
#         while(temp!=None):
#             temp_next = temp.next       #把temp的next地址给一个变量  
#             temp.next = last_temp
#             last_temp = temp
#             temp = temp_next    
#         return last_temp
# =============================================================================
# =============================================================================
# class Solution:
#     def removeNthFromEnd(self, head, n):
#         """
#         :type head: ListNode
#         :type n: int
#         :rtype: ListNode
#         """
#         if (Solution.doit(self, head, n)):
#             return head.next
#         return head
# 
#     def doit(self, head, n):
#         x = y = 0
#         if (head.next):     # 如果下个元素还有值
#             x = Solution.doit(self, head.next, n)
#             if (x):     # 如果下下个元素还有值
#                 y = x + 1 
#         else:
#             y = 1
#         if (y == n + 1):
#             head.next = head.next.next
#             y = 0
#         return y
# =============================================================================
# =============================================================================
# #     def __init__(self, x):
# #         self.val = x
# #         self.next = None
#     def deleteNode(self, head, node):
#         """
#         :type node: ListNode
#         :rtype: void Do not return anything, modify node in-place instead.
#         """
#         node.val=node.next.val #当前值被后一个值覆盖
#         node.next=node.next.next #下一节点跳到下下一节点
# =============================================================================
